﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		PageController.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System.Linq;
using System.Web.Mvc;
using Dexter.Logger.Contracts;
using Dexter.Search;
using Dexter.Services;
using Dexter.Web.Mvc.Filters;
using Dexter.Web.Mvc.ViewModel.FrontEnd.PageController;
using Dexter.Web.Utils;

namespace Dexter.Web.Mvc.Controllers.FrontEnd {
	[DexterCallFilter ( true )]
	public class PageController : PublicControllerBase {
		readonly IPageService pageService;

		public PageController ( ISearchService searchService , ICommentService commentService , IReferrerService referrerService , IConfigurationService configurationService , IWebUtils webUtils , ILogger logger , IUrlBuilder urlBuilder , IBlogRollService blogRollService , ICategoryService categoryService , IPostService postService , IThemeManager themeManager , ITagService tagService , IPageService pageService ) : base ( searchService , commentService , referrerService , configurationService , webUtils , logger , urlBuilder , blogRollService , categoryService , postService , themeManager , tagService , pageService ) {
			this.pageService = pageService;
		}

		[PingBack]
		[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
		public ActionResult Index ( string id ) {
			if ( string.IsNullOrEmpty ( id ) ) {
				return HttpNotFound ( );
			}

			var page = pageService.GetBySlug ( id );

			if ( page == null ) {
				return HttpNotFound ( );
			}

			var data = base.GetViewData ( new PageIndexViewData ( base.WebUtils , base.Configuration , base.UrlBuilder ) );
			data.Page = page;
			data.SetTitle ( page.Title );
			data.SetDescription ( page.Abstract );
			data.SetMetaKeywords ( page.Tags.Select ( x => x.Name ).ToArray ( ) );

			return View ( data );
		}
	}
}
